from rest_framework import serializers
from .models import Goods, GoodsCategory, GoodsImage
from django_filters import rest_framework as filters


class GoodsFilter(filters.FilterSet):
    price_max = filters.NumberFilter(field_name="shop_price", lookup_expr='gte')
    price_min = filters.NumberFilter(field_name="shop_price", lookup_expr='lte')

    class Meta:
        model = Goods
        fields = ['price_max', 'price_min' ]


class GoodsCategorySerializer3(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = "__all__"


class GoodsCategorySerializer2(serializers.ModelSerializer):
    sub_cat = GoodsCategorySerializer3(many=True)

    class Meta:
        model = GoodsCategory
        fields = "__all__"


class GoodsCategorySerializer(serializers.ModelSerializer):
    sub_cat = GoodsCategorySerializer2(many=True)

    class Meta:
        model = GoodsCategory
        fields = "__all__"


class GoodImagesSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsImage
        fields = ('image',)


class GoodsSerializer(serializers.ModelSerializer):
    category = GoodsCategorySerializer()
    images = GoodImagesSerializer(many=True)


    class Meta:
        model = Goods
        fields = "__all__"







